What is encapsulation? and why is use the encapsulation technique in OOPs?
What is encapsulation? and why is use the encapsulation technique in OOPs?
Hi, my self Ravi Vishwakarma. I have completed my studies at SPICBB Varanasi. now I completed MCA with 76% form Veer Bahadur Singh Purvanchal University Jaunpur.
SWE @ MindStick | Software Engineer | Web Developer | .Net Developer | Web Developer | Backend Engineer | .NET Core Developer
Aryan Kumar
06-Apr-2023Encapsulation is an important concept in object-oriented programming (OOP) that involves hiding the inner workings of an object from the outside world. This is done by restricting access to the object's data and methods through a well-defined interface.
In OOP, encapsulation is achieved through the use of classes that encapsulate data and methods. These classes act as blueprints for creating objects, each with their own unique set of data and methods.
Encapsulation is used in OOP to improve software design by reducing complexity and improving maintainability. By hiding the implementation details of an object, changes can be made to the implementation without affecting other parts of the program that use the object.
In addition to improving software design, encapsulation also helps to improve security by preventing unauthorized access to an object's data. This helps to ensure that the object behaves correctly and that the data is not accidentally or intentionally modified in unexpected ways.
Overall, encapsulation is an essential technique in modern software development that helps to improve software design, reduce complexity, and improve security.
In the Main class, we create a Person object and use the getter and setter methods to access and modify the object's data. This demonstrates how encapsulation can be used to hide the implementation details of an object and provide a well-defined interface for accessing and modifying its data.
Ashutosh Kumar Verma
31-Aug-2021Encapsulation -
Encapsulation is used to bind different methods and variables into a single units. A class is the best example to show the encapsulation technique which contain member methods and variables into a single class.
Use of Encapsulation - Encapsulation is used to protect the data from outer function which can change or remove of essential data or code. if we define a class with its properties (i.e. get and set methods), then we can change into the data but it not being changed into original data of that class.
Ex.
Output- Name is Ashu
Location is Vns